package com.qf.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author 千锋教育
 * @Company http://www.mobiletrain.org/
 * @Version 1.0
 */
public class MyInterceptor implements HandlerInterceptor {

    /**
     * 预处理： 方法执行之前执行
     * @param request
     * @param response
     * @param handler
     * @return  如果是false， 直接拦截，不执行（阻塞）  如果true，放行
     * @throws Exception
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("------------preHandler");
        return true;
    }

    /**
     * 方法执行之后执行，
     * 方法返回值返回之前执行此方法
     * @param request
     * @param response
     * @param handler
     * @param modelAndView
     * @throws Exception
     */
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        System.out.println("-----------PostHandler");
    }

    /**
     * 方法执行之后执行
     *
     *  方法返回值返回之后执行此方法
     *
     * @param request
     * @param response
     * @param handler
     * @param ex
     * @throws Exception
     */
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        System.out.println("--------------afterCompletion");
    }
}
